import { ref } from 'vue'
import { defineStore } from 'pinia'
import { localCache } from '@/utils/cache'

// 类型声明
export interface UserInfo {
  avatar?: string | undefined | File
  currentCoinCount: number
  expireTime: number
  fansCount?: number | null
  focusCount?: number | null
  nickName: string
  token: string
  userId: string
}

type UserInfoOrEmpty = UserInfo | null

export const useHomeStore = defineStore('home', () => {
  const isLogin = ref<boolean>(false)
  const userInfo = ref<UserInfoOrEmpty>()
  const gridNum = ref(10)
  const bodyMinWidth = ref(1250)
  const bodyMaxWidth = ref(2000)
  const sourcePath = ref('/api/file/getResource?sourceName=')
  const videoSourcePath = ref('/api/file/getVideoResource')
  const bodyPadding = ref(150)
  const carouseMaxCount = ref(1)
  //浏览器唯一标识ID
  const deviceId = ref<string>('')

  // 用户登录
  const login = async () => {}

  // 设置登录状态（
  const setLogin = (status: boolean) => {
    isLogin.value = status
  }

  //保存用户信息
  const saveUserInfo = (userInfoData: UserInfoOrEmpty) => {
    userInfo.value = userInfoData
  }

  //设置浏览器唯一标识ID
  const saveDeviceId = (id: string) => {
    deviceId.value = id
  }

  return {
    isLogin,
    userInfo,
    setLogin,
    saveUserInfo,
    login,
    sourcePath,
    gridNum,
    bodyMinWidth,
    bodyMaxWidth,
    bodyPadding,
    carouseMaxCount,
    deviceId,
    saveDeviceId,
    videoSourcePath
  }
})
